<%
sticky_button_classes ||= ''
without_fixed_button ||= false
options_param_name ||= :options
not_selected_options = product_not_selected_options(product, selected_variant, options_param_name: options_param_name)
all_options_selected = (params[options_param_name].present? || @variant_from_options.present?) && not_selected_options.empty?
not_all_options_selected = !all_options_selected && product.any_variant_available?(current_currency)
variant_not_available = selected_variant.nil? ||
                        product.discontinued? ||
                        selected_variant.discontinued? ||
                        !selected_variant.purchasable? ||
                        selected_variant.price_in(current_currency).amount.nil?
%>

<div class='<%= sticky_button_classes %> bottom-0 flex flex-col gap-4 z-10' data-sticky-button-target='stickyButton'>
  <%= button_tag type: (variant_not_available || not_all_options_selected ? 'button' : 'submit'),
                  class: 'btn-primary btn-icon w-full h-12 add-to-cart-button',
                  data: {
                    action: [
                      'click->product-form#showNotSelectedOptions',
                      ('click->modal#open' if variant_not_available)
                    ].compact.join(' '),
                    product_form_target: 'submit'
                  },
                  disabled: product.price_in(current_currency).zero? do %>
    <% if not_selected_options.size == 1 %>
      <span><%= Spree.t('storefront.variant_picker.please_choose', option_type: not_selected_options[0].presentation) %></span>
    <% elsif not_all_options_selected %>
      <span><%= Spree.t('storefront.variant_picker.please_choose_all_options') %></span>
    <% elsif variant_not_available %>
      <span><%= Spree.t(:notify_me_when_available) %></span>
      <%= render 'spree/shared/icons/bell' %>
    <% else %>
      <span><%= Spree.t(:add_to_cart) %></span>
      <%= render 'spree/shared/icons/cart' %>
    <% end %>
  <% end %>
</div>
<% unless without_fixed_button %>
  <div class='p-4 fixed-pdp-button bg-background fixed bottom-0 border-t border-default hidden w-full z-40 left-0' data-sticky-button-target='fixedButton'>
    <%= button_tag type: (variant_not_available || not_all_options_selected ? 'button' : 'submit'),
                  class: 'btn-primary btn-icon w-full h-12 add-to-cart-button',
                  data: {
                    action: [
                      'click->product-form#showNotSelectedOptions',
                      ('click->modal#open' if variant_not_available)
                    ].compact.join(' '),
                    product_form_target: 'submit'
                  },
                  disabled: product.price_in(current_currency).zero? do %>
      <% if not_selected_options.size == 1 %>
        <span><%= Spree.t('storefront.variant_picker.please_choose', option_type: not_selected_options[0].presentation) %></span>
      <% elsif not_all_options_selected %>
        <span><%= Spree.t('storefront.variant_picker.please_choose_all_options') %></span>
      <% elsif variant_not_available %>
        <span><%= Spree.t(:notify_me_when_available) %></span>
        <%= render 'spree/shared/icons/bell' %>
      <% else %>
        <span><%= Spree.t(:add_to_cart) %></span>
        <%= render 'spree/shared/icons/cart' %>
      <% end %>
    <% end %>
  </div>
<% end %>
